#ifndef ADMINWIDGET_H
#define ADMINWIDGET_H

#include <QWidget>
#include<QTreeView>
#include<QTableWidget>
#include<QSqlTableModel>
#include<QItemDelegate>
#include<QStandardItem>

namespace Ui {
class AdminWidget;
}

class AdminWidget : public QWidget
{
    Q_OBJECT

public:
    explicit AdminWidget(QWidget *parent = nullptr);
    ~AdminWidget();

    QStandardItem *currentItem;
    QMap<QString,QString> NameTypeMap;        //QMap方便数据的映射
    QString addName;
    QStringList listname;
    QList<int> listslid;
    QList<int> listdlid;
    QStringList header={"设备分类管理"};
    QString dicname;
    QString name;
    QString type;
    int refslid;            //定义全局变量
    int refdlid;

private slots:
    void on_tabWidget_currentChanged(int index);

    void soryByColumn(int col);
    void classifySortByColumn(int);
    void slotContextMenu(QPoint);
    void slotContextMenu2(QPoint);
    void slotContextMenu3(QPoint);
    void slotContextMenu4(QPoint);
    void slotContextMenu5(QPoint);
    void slotContextMenu6(QPoint);

    void on_pushButton_clicked();
    void on_pushButton_2_clicked();
    void on_pushButton_3_clicked();
    void on_pushButton_4_clicked();
    void on_pushButton_5_clicked();
    void on_pushButton_6_clicked();
    void on_pushButton_7_clicked();

    void slot_addRow();
    void slot_deleteRow();
    void slot_addRow2();
    void slot_deleteRow2();
    void slot_addRow3();
    void slot_deleteRow3();
    void slot_addRow4();
    void slot_deleteRow4();
    void slot_addRow5();
    void slot_deleteRow5();
    void slot_addRow6();
    void slot_deleteRow6();

private:
    Ui::AdminWidget *ui;
    bool initClassifyView();
    bool initTableView();
    bool initCheckTable();
    bool initReCheckTable();
    bool initMaintainTable();
    bool initLocationTable();
    bool initRestTable();

    QMenu *popMenu;
    QMenu *popMenu2;
    QMenu *popMenu3;
    QMenu *popMenu4;
    QMenu *popMenu5;
    QMenu *popMenu6;
    int selectCurrentRow;

    QStandardItemModel *model;

    void InitCombo();                       //初始化Combobox
    void ConnectDataBase();                 //连接数据库
    void LoadTree();                        //刷新树列表
    void reftree(QStandardItem*);           //递归遍历树
    void reftreechild(QStandardItem*,int&); //递归遍历子项
};

//class MySqlTableModel:public QSqlTableModel
//{
//public:
//    MySqlTableModel(QObject *parent=nullptr,QSqlDatabase db=QSqlDatabase());

//protected:
//    QString selectStatement() const override;
//};


class ComboDelegateYC : public QItemDelegate
{
    Q_OBJECT
public:
    ComboDelegateYC(QObject *parent = 0);
    int colRycchannel=2;

//任何代理类重写，都需要重写以下至少前三个函数
    QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;  //创建一个EDIT
    void setEditorData(QWidget *editor, const QModelIndex &index) const; //设置EDIT内的文本显示
    void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const; //设置edit内的data值（有时需要，有时不需要看情况）
//    void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const; //设置形状之类，可以省略
};
#endif // ADMINWIDGET_H
